package bma.common.langutil.log.acclog;

import org.slf4j.Logger;

public class AccessLogFactorySimple extends AccessLogFactoryAbstract {

	private org.slf4j.Logger log;

	public AccessLogFactorySimple() {
		super();
		log = org.slf4j.LoggerFactory.getLogger(AccessLogFactorySimple.class);
	}

	public AccessLogFactorySimple(Logger log) {
		super();
		this.log = log;
	}

	public org.slf4j.Logger getLog() {
		return log;
	}

	public void setLog(org.slf4j.Logger log) {
		this.log = log;
	}

	@Override
	public AccessLog create() {
		AccessLogAbstract r = new AccessLogAbstract() {

			@Override
			public boolean isWarnEnabled() {
				return log.isWarnEnabled();
			}

			@Override
			public boolean isInfoEnabled() {
				return log.isInfoEnabled();
			}

			@Override
			public boolean isDebugEnabled() {
				return log.isDebugEnabled();
			}

			@Override
			public void debug(String ltag, Object... args) {
				if (log.isDebugEnabled()) {
					log.debug(build(null, null, ltag, args));
				}
			}

			@Override
			public void info(String ltag, Object... args) {
				if (log.isInfoEnabled()) {
					log.info(build(null, null, ltag, args));
				}
			}

			@Override
			public void warn(String ltag, Object... args) {
				if (log.isWarnEnabled()) {
					log.warn(build(null, null, ltag, args));
				}
			}

			@Override
			protected void write(String s) {

			}

		};
		r.setId(nextId());
		r.setSeparator(separator);
		r.setSeparatorReplace(separatorReplace);
		return r;
	}
}
